﻿Imports System.Data.SqlClient

Public Class clsOrdenDetalleProductos
    Private mintIdMantenimiento As Integer
    Private mintIdProducto As Integer
    Private mstrCodigoProducto As String
    Private mstrNombreProducto As String
    Private mdblCantidad As Double
    Private mdblPrecioUnitario As Double
    Private mdblSubTotal As Double
    Private mdblIVA As Double
    Private mdblTotal As Double
    Private mstrAlmacen As String
    Private mstrNoParte As String
    Public Property IdMantenimiento() As Integer
        Get
            Return mintIdMantenimiento
        End Get
        Set(ByVal value As Integer)
            mintIdMantenimiento = value
        End Set
    End Property
    Public Property IdProducto() As Integer
        Get
            Return mintIdProducto
        End Get
        Set(ByVal value As Integer)
            mintIdProducto = value
        End Set
    End Property
    Public Property CodigoProducto() As String
        Get
            Return mstrCodigoProducto
        End Get
        Set(value As String)
            mstrCodigoProducto = value
        End Set
    End Property
    Public Property NombreProducto() As String
        Get
            Return mstrNombreProducto
        End Get
        Set(ByVal value As String)
            mstrNombreProducto = value
        End Set
    End Property
    Public Property Cantidad() As Double
        Get
            Return mdblCantidad
        End Get
        Set(ByVal value As Double)
            mdblCantidad = value
        End Set
    End Property
    Public Property PrecioUnitario() As Double
        Get
            Return mdblPrecioUnitario
        End Get
        Set(ByVal value As Double)
            mdblPrecioUnitario = value
        End Set
    End Property
    Public Property SubTotal() As Double
        Get
            Return mdblSubTotal
        End Get
        Set(ByVal value As Double)
            mdblSubTotal = value
        End Set
    End Property
    Public Property IVA() As Double
        Get
            Return mdblIVA
        End Get
        Set(ByVal value As Double)
            mdblIVA = value
        End Set
    End Property
    Public Property Total() As Double
        Get
            Return mdblTotal
        End Get
        Set(ByVal value As Double)
            mdblTotal = value
        End Set
    End Property
    Public Property Almacen As String
        Get
            Return mstrAlmacen
        End Get
        Set(value As String)
            mstrAlmacen = value
        End Set
    End Property
    Public Property NoParte As String
        Get
            Return mstrNoParte
        End Get
        Set(value As String)
            mstrNoParte = value
        End Set
    End Property
    Public Sub New()
        mintIdMantenimiento = 0
        mintIdProducto = 0
        mstrCodigoProducto = ""
        mstrNombreProducto = ""
        mdblCantidad = 0
        mdblPrecioUnitario = 0
        mdblSubTotal = 0
        mdblIVA = 0
        mdblTotal = 0
        mstrAlmacen = ""
        mstrNoParte = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into OrdenDetalleProductos (" & _
                            "IdMantenimiento," & _
                            "IdProducto," & _
                            "CodigoProducto," & _
                            "NombreProducto," & _
                            "Cantidad," & _
                            "PrecioUnitario," & _
                            "Subtotal," & _
                            "IVA," & _
                            "Total," & _
                            "Almacen," & _
                            "NoParte) " & _
                            "VALUES (" & _
                            "@IdMantenimiento," & _
                            "@IdProducto," & _
                            "substring(@CodigoProducto,1,50)," & _
                            "substring(@NombreProducto,1,200)," & _
                            "@Cantidad," & _
                            "@PrecioUnitario," & _
                            "@Subtotal," & _
                            "@IVA," & _
                            "@Total," & _
                            "substring(@Almacen,1,50)," & _
                            "substring(@NoParte,1,200)) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdMantenimiento", mintIdMantenimiento)
        Command.Parameters.AddWithValue("IdProducto", mintIdProducto)
        Command.Parameters.AddWithValue("CodigoProducto", mstrCodigoProducto)
        Command.Parameters.AddWithValue("NombreProducto", mstrNombreProducto)
        Command.Parameters.AddWithValue("Cantidad", mdblCantidad)
        Command.Parameters.AddWithValue("PrecioUnitario", mdblPrecioUnitario)
        Command.Parameters.AddWithValue("Subtotal", mdblSubTotal)
        Command.Parameters.AddWithValue("IVA", mdblIVA)
        Command.Parameters.AddWithValue("Total", mdblTotal)
        Command.Parameters.AddWithValue("Almacen", mstrAlmacen)
        Command.Parameters.AddWithValue("NoParte", mstrNoParte)
        

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
